package eu.connect.jmswrapper.callerproxies;

import java.io.Serializable;
import java.util.List;

import org.connect.enablers.discovery.goal.LTLFormula;
import org.connect.enablers.discovery.repository.CNSInstance;

import eu.connect.jmswrapper.*;
import eu.connect.mediatorSynthesis.synthesis.MediatorSynthesisInterface;
import eu.connect.mediatorSynthesis.synthesis.NoMediatorException;
import eu.connect.mediatorSynthesisOutput.ColouredAutomaton;

public class MediatorSynthesisInterfaceJMSCallerProxy extends
		ConnectJMSCallerProxy implements MediatorSynthesisInterface {

	@Override
	public ColouredAutomaton synthesiseAbstractMediator(CNSInstance ns1,
			CNSInstance ns2, List<LTLFormula> goals) throws NoMediatorException {

		ConnectJMSInvokeMessage invokeMsg = new ConnectJMSInvokeMessage();
		ConnectJMSReturnMessage returnMsg = null;
		
		invokeMsg.setMethodName("synthesiseAbstractMediator");
		invokeMsg.setParameterTypes(new Class[]{CNSInstance.class,CNSInstance.class,List.class});
		invokeMsg.setParameters(new Serializable[]{ns1,ns2,(Serializable)goals});
		
		try {
			ConnectJMSSender sender = new ConnectJMSSender(invokeMsg,"MediatorSynthesisInterface");
			returnMsg = sender.invoke();
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (returnMsg != null && returnMsg.isException())
			throw (NoMediatorException)returnMsg.getReturnObj();
		else if (returnMsg != null)
			return (ColouredAutomaton)returnMsg.getReturnObj();
		return null;
	}

}
